package com.dgj.xls.test;

import java.net.URI;
import java.net.URISyntaxException;

import org.java_websocket.client.WebSocketClient;
import org.java_websocket.drafts.Draft;
import org.java_websocket.drafts.Draft_17;
import org.java_websocket.handshake.ServerHandshake;

public class M extends WebSocketClient {

	public M(URI serverURI, Draft draft) {
		super(serverURI, draft);
	}

	@Override
	public void onOpen(ServerHandshake handshakedata) {
		System.out.println("opened connection");
	}

	@Override
	public void onMessage(String message) {
		System.out.println("received: " + message);
	}

	@Override
	public void onClose(int code, String reason, boolean remote) {
		System.out.println("Connection closed by " + (remote ? "remote peer" : "us"));
	}

	@Override
	public void onError(Exception ex) {
		ex.printStackTrace();
	}

	public static void main(String[] args) throws URISyntaxException, InterruptedException {
		M c = new M(new URI("ws://127.0.0.1:8080/byteslounge/websocket"), new Draft_17());
		c.connectBlocking();
		c.send("handshake");
	}

}
